#include"httplib.h"

using namespace httplib;
using namespace std;

void Hello(const Request & req , Response &rsp){
    rsp.set_content("hello weold!" , "text/plain");
    rsp.status = 200 ; 

}

void Numbers(const Request & req , Response &rsp){
    auto num = req.matches[1];//0保存的是整体path，往后下标中报春的也是捕捉的数据
    rsp.set_content(num , "text/plain");
    rsp.status = 200 ; 
}

void Multipart(const Request & req , Response &rsp){
    auto ret = req.has_file("file");
    if(ret == false){
        cout<<"not file upload\n";
        rsp.status = 400;
        return ;
    }
    const auto& file = req.get_file_value("file");
    rsp.body.clear();
    rsp.body = file.filename;//文件名称
    rsp.body+="\n";
    rsp.body+=file.content;//文件内容
    rsp.set_header("Content-Type" , "text/plain");
    rsp.status =200;
}
int main(void){
    Server server ;//实例化Server对象用于搭建服务器
    server.Get("/hi",Hello);//注册一个针对/hi的Get请求的处理函数映射关系
    server.Get(R"(/numbers/(\d+))" ,Numbers);
    server.Post("/mutipart" , Multipart);
    server.listen("0.0.0.0",9090);
    return 0;

}